layui.define([ 'form', 'laydate', 'table' ], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var coreTestdataTable = null;
    var view ={
        init:function(){
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function(){
                Lib.doSearchForm($("#searchForm"),coreTestdataTable);
                Lib.cleanSearchForm($("#searchForm"),coreTestdataTable);
            }
        },
        initTable:function(){
            coreTestdataTable = table.render({
                elem : '#coreTestdataTable',
                height : Lib.getTableHeight(1),
                cellMinWidth: 100,
                method : 'post',
                url : Common.ctxPath + '/cms/coreTestdata/list.json' // 数据接口
                ,page: true// 开启分页
                ,limit : 10,
                cols : [ [ // 表头
                    {
                        type : 'checkbox',
                        fixed:'left',
                    },
                {

                    field : 'id', 
                        title : 'id',
                    fixed:'left',
                        width : 60,
                },
                {

                    field : 'testName', 
                        title : '建筑(受检)单位名称',
                },
                {

                    field : 'address', 
                        title : '单位地址',
                },
                {

                    field : 'linkMan', 
                        title : '联系人',
                },
                {

                    field : 'linkPhone', 
                        title : '联系电话',
                },
                /*{

                    field : 'tester', 
                        title : '检测对象',
                },*/
                 {

                    field : 'stateText',
                        title : '状态',
                },
                /*{

                    field : 'fltype', 
                        title : '防雷类别',
                },
                {

                    field : 'testAddress',
                        title : '检测地点',
                },*/
                {

                    field : 'createTime', 
                        title : '创建时间',
                },
                {

                    field : 'testDate', 
                        title : '检测日期',
                        templet:function(d){
                            if(d.testDate)
                            return Common.getDate(d.testDate,'yyyy-MM-dd');
                            else return '';
                        },
                },
                {

                    field : 'reportDate', 
                        title : '报告发送日期',templet:function(d){
                                                                     if(d.reportDate)
                                                                     return Common.getDate(d.reportDate,'yyyy-MM-dd');
                                                                     else return '';
                                                                 },
                },

               /* {

                    field : 'type',
                        title : 'type',
                },*/
                {

                    field : 'approvlIdName',
                        title : '审批人',
                },
                {

                    field : 'remark', 
                        title : '审批备注',
                },
                {
                    fixed : 'right',
                    title : '操作',
                    align : 'center',
                    toolbar : '#toobar',
                    width:200
                 }
        ] ]

        });
            table.on('checkbox(coreTestdataTable)', function(obj){
                var coreTestdata = obj.data;
                if(obj.checked){
                    //按钮逻辑Lib.buttonEnable()
                }else{

                }
            })

        },
        initSearchForm:function(){
            Lib.initSearchForm( $("#searchForm"),coreTestdataTable,form);
        },
        initToolBar:function(){
            toolbar = {
                add : function() { // 获取选中数据
                    var url = "/cms/coreTestdata/add.do";
                    Common.openDlg(url,"检测数据管理>新增");
                },
                batchDel : function() {
                    layui.use(['del'], function(){
                        var delView = layui.del
                        delView.delBatch();
                    });
                }
               };

            //监听工具条
            layui.table.on('tool(coreTestdataTable)', function(obj) {
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if(layEvent === 'approval' || layEvent=='approvalReport'){
                   layer.open({
                       type: 1
                       ,title: false //不显示标题栏
                       ,closeBtn: false
                       ,area: '300px;'
                       ,shade: 0.8
                       ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                       ,btn: ['审核通过', '审核拒绝']
                       ,btnAlign: 'c'
                       ,moveType: 1 //拖拽模式，0或者1
                       ,content: '<div style="padding: 30px 10px;"><textarea id="remark" style="width:100%;height:200px" placeholder="请填写审核备注"></textarea></div>'
                       ,yes: function(){
                         approval(data.id,$("#remark").val(),layEvent === 'approval'?1:4);
                       }
                       ,btn2: function(){
                         approval(data.id,$("#remark").val(),layEvent === 'approval'?5:6);
                       }

                     });
                }else if(layEvent=='del') {
                    layui.use(['del'], function(){
                        var delView = layui.del;
                        delView.delRow(data);
                    });
                }else if(layEvent=='detail') {
                     var url = "/cms/coreTestdata/detail.do?id="+data.id;
                     Common.openDlg(url,"检测数据管理>详情");
                 }
            });
            $('.ext-toolbar').on('click', function() {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
     };
    exports('index',view);

});